package com.example.weatherforecast.weatherdatatool;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * @Author：coderChen
 * @Package：com.example.weatherforecast.weathertool
 * @Project：WeatherForecast
 * @Date：2024/1/2 19:32
 * @Filename：WeatherDataParser
 */

public class WeatherDataParser {
    public static String parseDate(String date) {
        Pattern pattern = Pattern.compile("(\\d{4})-(\\d{2})-(\\d{2})");
        Matcher matcher = pattern.matcher(date);
        String month = "", day = "";
        if (matcher.find()) {
            month = matcher.group(2); // 获取匹配到的月份部分
            day = matcher.group(3); // 获取匹配到的日期部分
        }
        return month + "月" + day + "日"; // 格式化月份和日期
    }

    public static String parseTemperature(String temperature) {
        Pattern pattern = Pattern.compile("\\-?\\d+℃");
        Matcher matcher = pattern.matcher(temperature);
        if (matcher.find()) {
            return matcher.group(); // 获取匹配到的温度部分
        }
        return ""; // 如果没有匹配到温度，则返回空字符串或者其他默认值
    }
}

